﻿@Html.Partial("_ViewCustomerPartial")
<div style="text-align: right;">
    <button type="button" class="btn btn-default" onclick="onCustomerSelected();">Chọn</button>
</div>

<script>
    function onCustomerSelected() {
        var obj = getSelectedObj();
        if (!obj) {
            alert("Bạn chưa chọn khách hàng");
        }
        $("#CustomerId").val(obj.Id);
        $("#CustomerName").val(obj.CustomerName);
        $('#editWindow').modal('hide');
    }
    function getSelectedObj() {
        var elements = $("#list input[type='checkbox']:checked").parent().parent();
        if (elements.length == 0)
            return null;
        var firstElement = elements[0];
        return {
            Id: $(firstElement).attr("id"),
            CustomerName: $(firstElement).find("td[aria-describedby='list_CustomerName']").text()
        };
    }
</script>
